<?php
global $_GPC, $_W;
$GLOBALS['frames'] = $this->getMainMenu();
$op = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
load()->func('tpl');
$shset=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
$pageindex = max(1, intval($_GPC['page']));
$pagesize=10;
// if (!empty($_GPC['status'])) {
//     $where=' WHERE  uniacid=:uniacid ';
//     $data[':uniacid']=$_W['uniacid'];
//     if(isset($_GPC['keywords'])){
//         $where.="  and (name LIKE  concat('%', :name,'%') or phone LIKE  concat('%', :name,'%'))";
//         $data[':name']=$_GPC['keywords']; 
//     }
//     $active=$_GPC['status'];
//     $sql="SELECT * FROM ".tablename('zh_gjw_visit') .$where." ORDER BY time desc";
//     $total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_visit').$where." ORDER BY time desc",$data);
// }else{
    $where=' WHERE  uniacid=:uniacid  ';
    $data[':uniacid']=$_W['uniacid'];
    if(isset($_GPC['keywords'])){
        $where.="  and (name LIKE  concat('%', :name,'%') or phone LIKE  concat('%', :name,'%'))";
        $data[':name']=$_GPC['keywords']; 
    }
    // $active=$_GPC['status'];
    $sql="SELECT * FROM ".tablename('zh_gjw_visit') .$where." ORDER BY time desc";
    $total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_visit').$where." ORDER BY time desc",$data);
// }
$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
$registers=pdo_fetchall($select_sql,$data);
$pager = pagination($total, $pageindex, $pagesize);

if($op=='delete'){
    $res=pdo_delete('zh_gjw_visit',array('id'=>$_GPC['id']));
    // var_dump($res);die;
    if($res){
      message('删除成功',$this->createWebUrl('visit',array()),'success');
    }else{
      message('删除失败','','error');
    }
}
  
    

include $this->template('web/visit');